﻿using Infrastructure.States;
using Logic;
using UI.Support;
using UnityEngine;

namespace UI
{
    public class PauseWindow : BaseWindow
    {
        private GameStateMachine _stateMachine;
        [SerializeField] private ButtonClick _exitButton;

        public void Construct(GameStateMachine stateMachine) =>
            _stateMachine = stateMachine;

        protected override void OnAwake()
        {
            base.OnAwake();
            _exitButton.Clicked += EndGame;
            Time.timeScale  = 0;
        }

        private void OnDestroy() =>
            Time.timeScale   =  1;

        private void EndGame() =>
            _stateMachine.Enter<LoadEndGameState, string>(Constants.EndGame);
    }
}